package com.memory.servlet;

import com.memory.dao.impl.UserDaoImpl;
import com.memory.pojo.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet(urlPatterns = "/DeleteServlet")
public class DeleteServlet extends HttpServlet {
    UserDaoImpl userDao = new UserDaoImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 1.根据id查找学生数据删除数据
        UserDaoImpl userDao = new UserDaoImpl();
        List<User> userlist=null;
        String sno = request.getParameter("Sno");
        Integer Sno =Integer.parseInt(sno) ;
        try {
            userDao.delete(Sno);
            userlist = userDao.selectAll();

        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        request.setAttribute("userList",userlist);
        request.getRequestDispatcher("userList.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}